﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System .IO;
namespace Person
{
    class Program
    {
        static void Main(string[] args)
        {
            //Driveinfo获取驱动器信息


            DriveInfo driveInfo = new DriveInfo("D");
            Console.WriteLine("驱动器名称：" + driveInfo.Name);
            Console.WriteLine("驱动器总空间大小" + driveInfo.TotalSize);
            Console.WriteLine("驱动器可用空闲时间：" + driveInfo.AvailableFreeSpace);
            Console.WriteLine("驱动器类型：" + driveInfo.DriveType);

            //Directoryinfo文件夹操作

            DirectoryInfo directoryInfo = new DirectoryInfo("D:\\person");
            directoryInfo.Create();//创建文件夹
            directoryInfo.CreateSubdirectory("git1");//指定路径创建子目录
            directoryInfo.CreateSubdirectory("git2");
            directoryInfo.Delete(true);

            IEnumerable<DirectoryInfo> dir = directoryInfo.EnumerateDirectories();//查看person文件夹下子文件夹
            foreach (var s in dir)
            {
                Console.WriteLine(s.Name);
            }


            //Directory文件夹操作

            bool file = Directory.Exists("D:\\person");
            if (file)
            {
                Directory.Delete("D:\\person", true);//删除
            }
            else
            {
                Directory.CreateDirectory("D:tach");//创建
            }


            //FileInfo类

            Directory.CreateDirectory("D:\\fead");
            FileInfo fileInfo = new FileInfo("D:\\fead\\studen");//D盘下创建子文件

            if (!fileInfo.Exists)//判断是否有文件
            {
                fileInfo.Create().Close();//创建并删除
            }
            else
            {
                fileInfo.MoveTo("D:\\person");//转移到指定文件
            }

            Console.WriteLine("文件名称：" + fileInfo.Name);
            Console.WriteLine("文件长度：" + fileInfo.Length);
            Console.WriteLine("是否可读：" + fileInfo.IsReadOnly);



            //File类

            Directory.CreateDirectory("D:\\wood");
            string pa = "D:\\wood\\have";
            FileStream fi = File.Create(pa);  //创建文件夹

            Console.WriteLine("文件夹创建时间和日期：" + File.GetCreationTime(pa));
            Console.WriteLine("上次文件夹访问时间：" + File.GetLastAccessTime(pa));


            //Path类

            Console.WriteLine("原本路径字符串扩展名");
            Path.GetExtension(("D:\\wood"));

            string Newpa = Path.ChangeExtension(pa, "air");
            Console.WriteLine("改了以后的扩展名" + Path.GetFileName(Newpa)); //返回指定路径字符串的文件名和扩展名

            Console.WriteLine("返回指定路径字符串的目录信息");
            Path.GetDirectoryName("D:\\person");

            Console.WriteLine("返回指定路径字符串的绝对路径");
            Path.GetFullPath("D:\\fead");

        }
    }
}
